package service

import (
	"context"
	"mini-app/internal/app/grpc/common"
	"mini-app/internal/dal"
	"mini-app/internal/dao"
	"mini-app/internal/models"

	"192.168.1.75/go-pkg/logx"
)

type Order struct{}

// List 订单列表
func (Order) List(ctx context.Context, orderID string, orderStatus int, page, limit int) (list []*models.Order, total int64, err error) {

	logx.Error(ctx, "Order List Mini App", logx.Any("orderID", orderID))
	list, total, err = dao.Order{}.OrderList(
		ctx,
		dal.Q,
		"",
		"",
		orderID,
		"",
		"",
		orderStatus,
		page, limit,
	)
	if err == nil && total > 0 {
		for k, v := range list {
			// 获取机器商品图片
			goodsList, _ := common.GRPC{}.GetGoodsList(ctx, v.RobotID, 0, 0, "", "", 0, 0)
			for _, goods := range goodsList {
				if goods.GoodsId == v.GoodsID {
					list[k].GoodsImage = goods.GoodsImage
				}
			}
		}
	}
	return
}
